package com.woniuxy.ticket_cinema.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.ticket_cinema.entity.*;
import com.woniuxy.ticket_cinema.mapper.*;
import com.woniuxy.ticket_cinema.service.Schedule_seatService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author booty
 * @since 2021-02-22
 */
@Service
public class Schedule_seatServiceImpl extends ServiceImpl<Schedule_seatMapper, Schedule_seat> implements Schedule_seatService {

    @Resource
    private Schedule_seatMapper schedule_seatMapper;
    @Resource
    private ScheduleMapper scheduleMapper;
    @Resource
    private SeatMapper seatMapper;
    @Resource
    private HallMapper hallMapper;
    @Resource
    private CinemaMapper cinemaMapper;

    //下订单时，通过排片-座位中间表返回的信息
    @Override
    @Transactional
    public String findToOrderById(int id) {
        Schedule_seat schedule_seat = schedule_seatMapper.selectById(id);

        //排片id
        Integer scheduleId = schedule_seat.getScheduleId();
        //座位id
        Integer seatId = schedule_seat.getSeatId();

        //锁定座位，修改座位状态
        if (schedule_seatMapper.updateStatus(scheduleId, seatId) > 0) {
            System.out.println(11111);
            //通过排片id去查询价格price
            Schedule schedule = scheduleMapper.selectById(scheduleId);
            BigDecimal price = schedule.getPrice();
            String priceName = price.toString();

            //通过座位id去查询影厅hall 座位seat
            Seat seat = seatMapper.selectById(seatId);
            String seatName = seat.getRowno() + "排" + seat.getColno() + "列";

            Hall hall = hallMapper.selectById(seat.getHallId());
            String hallName = hall.getName() + "(" + hall.getType() + ")";

            //通过影厅中的影院id去查询影院cinema
            Cinema cinema = cinemaMapper.selectById(hall.getCinemaId());
            String cinemaName = cinema.getName();

            //封装数据返回给Order，服务端无法接收List等，用String封装
            String str = priceName + "," + cinemaName + "," + hallName + "," + seatName;

            return str;

        }
        return null;
    }
}
